<?php

/**
 * 商城首页接口
 *
 * @author: yeyu <409166486@qq.com> 2016-11-11
 */
class Api_Home extends PhalApi_Api
{

    public function getRules()
    {
        return array(
            'getAllDef' => array()
        );
    }


    /**
     * 首页数据接口
     * @return array shopConfig 商城基本配置
     * @return array productLists 默认展示的商品
     */
    public function getAllDef()
    {
        $rs = array('productLists' => array(), 'shopConfig' => array(), 'productImages' => array(), "allTongjiObj" => array(), "onlineService" => array());

        $domainP = new Domain_Product();

        $rs['productLists'] = $domainP->getAllDefProducts();


        $domainT = new Domain_Tongji();
        $rs['allTongjiObj'] = $domainT->getAll();

        $domainS = new Domain_Service();
        $rs['onlineService'] = $domainS->get();

        $domainStore = new Domain_Store();
        $shopConfig = $domainStore->getConfig();

        $rs['shopConfig'] = $shopConfig;

        $imgs = $shopConfig['advert_imgs'];
        if ($imgs) {
            $defImg = explode("||", $imgs);
            $defImgs = array();
            foreach ($defImg as $img) {
                //所有图片都是存在云服务器 所以都是外部一个链接
                $defImgs[] = $img;
            }
        }

        $rs['productImages'] = $defImgs;

        return $rs;
    }
}
